Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix crash on type assert on empty interface #3986

Merged
merged 1 commit into from
Nov 8, 2023

Conversation

dgryski
Copy link
Member

@dgryski dgryski commented Nov 4, 2023

No description provided.

@dgryski dgryski requested a review from aykevl November 4, 2023 17:15
@dgryski
Copy link
Member Author

dgryski commented Nov 4, 2023

Does this look like a better fix to #3788 ?

@dgryski
Copy link
Member Author

dgryski commented Nov 4, 2023

I'll update this PR with the following test:

~/go/src/github.com/dgryski/bug/intf $ tinygo-old run main.go
panic: interp: offset out of range

goroutine 52 [running]:
github.com/tinygo-org/tinygo/interp.pointerValue.addOffset(...)
	/Users/dgryski/go/src/github.com/tinygo-org/tinygo/interp/memory.go:523
github.com/tinygo-org/tinygo/interp.(*runner).run(0xc001284640, 0xc0012c0050, {0xc0012a0590, 0x1, 0x0?}, 0xc0012809f0, {0xc0012ca0a8, 0x8})
	/Users/dgryski/go/src/github.com/tinygo-org/tinygo/interp/interpreter.go:427 +0x7865
github.com/tinygo-org/tinygo/interp.(*runner).run(0xc001284640, 0xc0012c0000, {0x0, 0x0, 0x0?}, 0x0, {0x104853bba, 0x4})
	/Users/dgryski/go/src/github.com/tinygo-org/tinygo/interp/interpreter.go:526 +0x7ccc
github.com/tinygo-org/tinygo/interp.RunFunc({0xc0032382a0?}, 0xc0012b7ce0?, 0x40?)
	/Users/dgryski/go/src/github.com/tinygo-org/tinygo/interp/interp.go:237 +0x3a5
github.com/tinygo-org/tinygo/builder.Build.func3(0xc000fc2f00)
	/Users/dgryski/go/src/github.com/tinygo-org/tinygo/builder/build.go:449 +0xc76
github.com/tinygo-org/tinygo/builder.runJob(0xc000fc2f00, 0x4364657469726568?)
	/Users/dgryski/go/src/github.com/tinygo-org/tinygo/builder/jobs.go:222 +0x4d
created by github.com/tinygo-org/tinygo/builder.runJobs in goroutine 1
	/Users/dgryski/go/src/github.com/tinygo-org/tinygo/builder/jobs.go:123 +0x5bd
~/go/src/github.com/dgryski/bug/intf $ tinygo run main.go
x is 5
~/go/src/github.com/dgryski/bug/intf $ cat main.go
package main

func main() {
}

type myint int

func init() {
	if x, ok := any(5).(any); ok {
		println("x is", x.(int))
	}
}

@aykevl
Copy link
Member

aykevl commented Nov 8, 2023

This looks like a good fix.
Can you add the test somewhere? For example, to testdata/interface.go.

@dgryski dgryski force-pushed the dgryski/empty-intf-crash branch from a0b9123 to 9ff3754 Compare November 8, 2023 15:33
@dgryski dgryski marked this pull request as ready for review November 8, 2023 15:33
@dgryski dgryski changed the title WIP: fix crash on type assert on empty interface fix crash on type assert on empty interface Nov 8, 2023
@dgryski
Copy link
Member Author

dgryski commented Nov 8, 2023

Test added.

@dgryski dgryski force-pushed the dgryski/empty-intf-crash branch from 9ff3754 to 9b0c8a7 Compare November 8, 2023 15:43
@deadprogram
Copy link
Member

Thanks for the fix on this @dgryski and to @aykevl for review. Now merging.

@deadprogram deadprogram merged commit 777048c into tinygo-org:dev Nov 8, 2023
15 checks passed
@gggrafff gggrafff mentioned this pull request Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants